﻿using OnlineOrder.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OnlineOrder.UI
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //返回登录界面
            LoginForm loginForm = new LoginForm();
            this.Hide();
            loginForm.ShowDialog();
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //注册
            string username = this.textBox1.Text;
            string password = this.textBox2.Text;
            string name = this.textBox3.Text;
            string sex = this.radioButton1.Checked ? "男":"女" ;
            string tele = this.textBox4.Text;
            string place = this.textBox5.Text;

            try
            {
                //SQL语句
                string sql = string.Format($"insert User into values('{username}','{password}','{name}','{sex}','{tele}','{place}')");

                //返回受影响行数,连接数据库并执行sql
                int i = Utils.SqlHelper.ExecuteNonQuery(sql);

                if ( i > 0 )
                {
                    MessageBox.Show("注册成功！");
                }
                else 
                {
                    MessageBox.Show("你填写的格式有误，请重新输入");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void RegisterForm_Load(object sender, EventArgs e)
        {

        }
    }
}
